/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Vendas.java
 *
 * Created on 19/08/2010, 09:57:10
 */
package view;

import DAO.ClienteDAO;
import DAO.FornecedorDAO;
import DAO.ProdutoDAO;
import DAO.VendaDAO;
import controller.Cliente;
import controller.Fornecedor;
import controller.Produto;
import controller.Venda;
import java.awt.Dimension;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Alcivando
 */
public class Vendas extends javax.swing.JInternalFrame {

    int valorVenda;
    DefaultTableModel modeloProdutoSelecionado;
    DefaultTableModel modeloPesquisaCliente;
    DefaultTableModel modeloPesquisaProduto;
    ArrayList<Produto> listaProduto;
    VendaDAO dao;
    Venda venda;
    private static final Vendas vendas;

    static {
        vendas = new Vendas();
    }

    public static Vendas getInstancia() {
        return vendas;
    }

    /** Creates new form Vendas */
    public Vendas() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel5 = new javax.swing.JPanel();
        btnNovo = new javax.swing.JButton();
        btnSalvar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        boxTipoPagamento = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        txtData = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jPanel7 = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        tabProdutoSelecionados = new javax.swing.JTable();
        jPanel6 = new javax.swing.JPanel();
        txtPesquisaProduto = new javax.swing.JTextField();
        jScrollPane4 = new javax.swing.JScrollPane();
        tabPesquisaProduto = new javax.swing.JTable();
        jLabel3 = new javax.swing.JLabel();
        btnAddProduto = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        filtroP = new javax.swing.JComboBox();
        txtQtd = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        txtNomeCliente = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txtCodigocliente = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jTabbedPane3 = new javax.swing.JTabbedPane();
        jPanel9 = new javax.swing.JPanel();
        txtPesquisaCliente = new javax.swing.JTextField();
        filtro = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane6 = new javax.swing.JScrollPane();
        tabPesquisaCliente = new javax.swing.JTable();
        jPanel8 = new javax.swing.JPanel();
        rotValorVenda = new javax.swing.JLabel();
        rotParcela = new javax.swing.JPanel();
        lValorTotal1 = new javax.swing.JLabel();
        nParcelas = new javax.swing.JComboBox();
        jLabel13 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        rotValorParcela = new javax.swing.JTextPane();

        setClosable(true);
        setIconifiable(true);
        setTitle("Controle de Vendas");

        jPanel5.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        btnNovo.setFont(new java.awt.Font("Tahoma", 1, 12));
        btnNovo.setText("Novo ");
        btnNovo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnNovo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNovoActionPerformed(evt);
            }
        });

        btnSalvar.setFont(new java.awt.Font("Tahoma", 1, 12));
        btnSalvar.setText("Salvar");
        btnSalvar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnSalvar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalvarActionPerformed(evt);
            }
        });

        btnCancelar.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnNovo, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(41, Short.MAX_VALUE))
        );

        jPanel5Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnCancelar, btnNovo, btnSalvar});

        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(btnCancelar, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(btnSalvar, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE)
                            .addComponent(btnNovo, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE))
                        .addGap(206, 206, 206))))
        );

        jPanel5Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btnCancelar, btnNovo, btnSalvar});

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Tipo de pagamento e Data ", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        boxTipoPagamento.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Á vista", "Á vista no cartão", "Á prazo" }));
        boxTipoPagamento.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                boxTipoPagamentoActionPerformed(evt);
            }
        });

        jLabel11.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel11.setText("Tipo de Pagamento");

        jLabel12.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel12.setText("Data");

        txtData.setEnabled(false);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(boxTipoPagamento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11))
                .addGap(27, 27, 27)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel12)
                    .addComponent(txtData, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(154, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(boxTipoPagamento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Dados Produto", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Produtos Selecionados", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        tabProdutoSelecionados.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tabProdutoSelecionados.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabProdutoSelecionadosMouseClicked(evt);
            }
        });
        jScrollPane5.setViewportView(tabProdutoSelecionados);

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 298, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(14, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Pesquisar Produtos", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        txtPesquisaProduto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtPesquisaProdutoActionPerformed(evt);
            }
        });
        txtPesquisaProduto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtPesquisaProdutoKeyReleased(evt);
            }
        });

        tabPesquisaProduto.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tabPesquisaProduto.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabPesquisaProdutoMouseClicked(evt);
            }
        });
        jScrollPane4.setViewportView(tabPesquisaProduto);

        jLabel3.setText("Pesquisarpor:");

        btnAddProduto.setText("adicionar produto");
        btnAddProduto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddProdutoActionPerformed(evt);
            }
        });

        jLabel1.setText("*Quantidade: ");

        filtroP.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "nome", "tamanho", "marca" }));

        txtQtd.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtQtdKeyReleased(evt);
            }
        });

        jLabel2.setText("* No campo da Quantidade, somente números");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(jPanel6Layout.createSequentialGroup()
                            .addComponent(jLabel1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(txtQtd, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(btnAddProduto))
                        .addGroup(jPanel6Layout.createSequentialGroup()
                            .addComponent(jLabel3)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(filtroP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(txtPesquisaProduto))
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 312, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel2))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(filtroP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtPesquisaProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtQtd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnAddProduto, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel2)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel7, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(20, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Dados do Cliente", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        txtNomeCliente.setEnabled(false);
        txtNomeCliente.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtNomeClienteKeyReleased(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel6.setText("Nome do Cliente");

        txtCodigocliente.setEditable(false);

        jLabel10.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel10.setText("Código");

        txtPesquisaCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtPesquisaClienteActionPerformed(evt);
            }
        });
        txtPesquisaCliente.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtPesquisaClienteKeyReleased(evt);
            }
        });

        filtro.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Nome", "Código", "CPF" }));

        jLabel4.setText("Pesquisar pelo");

        tabPesquisaCliente.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tabPesquisaCliente.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabPesquisaClienteMouseClicked(evt);
            }
        });
        jScrollPane6.setViewportView(tabPesquisaCliente);

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 326, Short.MAX_VALUE)
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(filtro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtPesquisaCliente, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(filtro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtPesquisaCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane3.addTab("Pesquisar Clientes", jPanel9);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTabbedPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 351, Short.MAX_VALUE)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtCodigocliente, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel10))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(txtNomeCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(txtNomeCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel4Layout.createSequentialGroup()
                            .addGap(19, 19, 19)
                            .addComponent(txtCodigocliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(jLabel10))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(22, Short.MAX_VALUE))
        );

        jPanel8.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Valor da Venda", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        rotValorVenda.setFont(new java.awt.Font("Tahoma", 1, 18));

        javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addGap(120, 120, 120)
                .addComponent(rotValorVenda, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(121, Short.MAX_VALUE))
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel8Layout.createSequentialGroup()
                .addComponent(rotValorVenda, javax.swing.GroupLayout.DEFAULT_SIZE, 49, Short.MAX_VALUE)
                .addContainerGap())
        );

        rotParcela.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Parcelamento", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        lValorTotal1.setFont(new java.awt.Font("Tahoma", 1, 18));

        nParcelas.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5" }));
        nParcelas.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                nParcelasItemStateChanged(evt);
            }
        });

        jLabel13.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel13.setText("Nº Parcelas");

        rotValorParcela.setEditable(false);
        rotValorParcela.setFont(new java.awt.Font("Tahoma", 1, 24));
        rotValorParcela.setEnabled(false);
        jScrollPane1.setViewportView(rotValorParcela);

        javax.swing.GroupLayout rotParcelaLayout = new javax.swing.GroupLayout(rotParcela);
        rotParcela.setLayout(rotParcelaLayout);
        rotParcelaLayout.setHorizontalGroup(
            rotParcelaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(rotParcelaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(rotParcelaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel13)
                    .addComponent(nParcelas, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(rotParcelaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(rotParcelaLayout.createSequentialGroup()
                        .addGap(64, 64, 64)
                        .addComponent(lValorTotal1))
                    .addGroup(rotParcelaLayout.createSequentialGroup()
                        .addGap(40, 40, 40)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(121, Short.MAX_VALUE))
        );
        rotParcelaLayout.setVerticalGroup(
            rotParcelaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(rotParcelaLayout.createSequentialGroup()
                .addGroup(rotParcelaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(rotParcelaLayout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(52, 52, 52)
                        .addComponent(lValorTotal1))
                    .addGroup(rotParcelaLayout.createSequentialGroup()
                        .addComponent(jLabel13)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(nParcelas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(rotParcela, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(rotParcela, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNovoActionPerformed

        txtCodigocliente.setText("");
        txtNomeCliente.setText("");
        txtPesquisaCliente.setText("");
        txtPesquisaProduto.setText("");

        String data = new SimpleDateFormat("dd/MM/yyyy").format(new Date()).toString();
        txtData.setText(data);


        valorVenda = 0;

        btnNovo.setEnabled(false);
        btnCancelar.setEnabled(true);
        btnSalvar.setEnabled(true);

        txtPesquisaCliente.setEnabled(true);
        txtPesquisaProduto.setEnabled(true);
        txtCodigocliente.setEnabled(false);
        txtNomeCliente.setEnabled(false);
        txtQtd.setEnabled(true);
        filtro.setEnabled(true);

        btnAddProduto.setEnabled(true);
        boxTipoPagamento.setEnabled(true);


        tabPesquisaCliente.setEnabled(true);
        tabPesquisaProduto.setEnabled(true);
        tabProdutoSelecionados.setEnabled(true);

    }//GEN-LAST:event_btnNovoActionPerformed

    private void btnSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalvarActionPerformed
        try {
            listaProduto = new ArrayList<Produto>();

            Calendar data = new GregorianCalendar();

            String dataHoje = data.get(data.DAY_OF_MONTH) + "/" + (data.get(data.MONTH)) + "/" + data.get(data.YEAR);

            data.add(Calendar.DAY_OF_MONTH, 30);

            String dataParcela = data.get(data.DAY_OF_MONTH) + "/" + (data.get(data.MONTH) + 1) + "/" + data.get(data.YEAR);

            int contador = tabProdutoSelecionados.getRowCount();

            ProdutoDAO pdao = new ProdutoDAO();
            Produto p = new Produto();

            for (int i = 0; i < contador; i++) {

                p = pdao.retornaProdutoPorCodigo(Integer.parseInt(tabProdutoSelecionados.getValueAt(i, 0).toString()));
                p.setQuantidade(Integer.parseInt(tabProdutoSelecionados.getValueAt(i, 3).toString()));

                listaProduto.add(p);

            }

            dao = new VendaDAO();

            venda = new Venda();

            venda.setTotal(Double.parseDouble(rotValorVenda.getText()));
            venda.setData(dataHoje);
            venda.setValorParcela(Double.parseDouble(rotValorParcela.getText()));
            venda.setnParcelas(Integer.parseInt(nParcelas.getSelectedItem().toString()));
            venda.setVencimentoParcela(dataParcela);
            venda.setCodCliente(Integer.parseInt(txtCodigocliente.getText()));
            if (boxTipoPagamento.getSelectedItem().toString().equals("Á vista")) {
                venda.setTipoPagamento("Á vista");
            } else if (boxTipoPagamento.getSelectedItem().toString().equals("Á vista no cartão")) {
                venda.setTipoPagamento("Á vista no cartão");
            } else {
                venda.setTipoPagamento("Á prazo");
            }

            dao.adiciona(venda, listaProduto);

            if (boxTipoPagamento.getSelectedItem().toString().equals("Á prazo")) {

                ClienteDAO cdao = new ClienteDAO();

                cdao.adicionarValorConta(Integer.parseInt(txtCodigocliente.getText()), Double.parseDouble(rotValorVenda.getText()));

            }

            btnSalvar.setEnabled(false);
            btnNovo.setEnabled(true);
            btnCancelar.setEnabled(false);

            txtNomeCliente.setEnabled(false);
            txtPesquisaCliente.setEnabled(false);
            txtPesquisaProduto.setEnabled(false);
            txtQtd.setEnabled(false);

            btnAddProduto.setEnabled(false);

            tabPesquisaCliente.setEnabled(false);
            tabPesquisaProduto.setEnabled(false);
            tabProdutoSelecionados.setEnabled(false);

            txtCodigocliente.setText("");
            txtNomeCliente.setText("");
            txtPesquisaCliente.setText("");
            txtPesquisaProduto.setText("");
            txtQtd.setText("");
            modeloProdutoSelecionado.setNumRows(0);
            modeloPesquisaCliente.setNumRows(0);
            modeloPesquisaProduto.setNumRows(0);

            JOptionPane.showMessageDialog(null, "Salvo com sucesso!", "Cadastro Concluído", 1);

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Erro: " + ex.getMessage(), "Erro", 0);
        }
    }//GEN-LAST:event_btnSalvarActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed

        txtCodigocliente.setText("");
        txtNomeCliente.setText("");
        txtPesquisaCliente.setText("");
        txtPesquisaProduto.setText("");
        btnNovo.setEnabled(true);
        btnSalvar.setEnabled(false);
        btnCancelar.setEnabled(false);
        btnAddProduto.setEnabled(false);
        boxTipoPagamento.setEnabled(false);
        filtro.setEnabled(false);

        modeloProdutoSelecionado.setNumRows(0);
        modeloPesquisaCliente.setNumRows(0);
        modeloPesquisaProduto.setNumRows(0);

        txtCodigocliente.setEnabled(false);
        txtNomeCliente.setEnabled(false);
        txtPesquisaCliente.setEnabled(false);
        txtPesquisaProduto.setEnabled(false);
        txtQtd.setEnabled(false);
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void boxTipoPagamentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_boxTipoPagamentoActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_boxTipoPagamentoActionPerformed

    private void tabProdutoSelecionadosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabProdutoSelecionadosMouseClicked
    }//GEN-LAST:event_tabProdutoSelecionadosMouseClicked

    private void txtPesquisaProdutoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtPesquisaProdutoKeyReleased

        txtQtd.setText("");
        modeloPesquisaProduto.setNumRows(0);

        ArrayList<Produto> listaProduto;

        try {
            ProdutoDAO pdao = new ProdutoDAO();
            if (!txtPesquisaProduto.getText().isEmpty()) {

                if (filtroP.getSelectedItem().toString().equals("nome")) {
                    listaProduto = pdao.retornaProdutoPorNome(txtPesquisaProduto.getText().toUpperCase());
                } else if (filtroP.getSelectedItem().toString().equals("tamanho")) {
                    listaProduto = pdao.retornaProdutoPorCod(Integer.parseInt(txtPesquisaProduto.getText().toUpperCase()));
                } else {
                    listaProduto = pdao.retornaProdutoPorPreco(Double.parseDouble(txtPesquisaProduto.getText().toUpperCase()));
                }

                for (Produto p : listaProduto) {
                    FornecedorDAO fdao = new FornecedorDAO();
                    Fornecedor f = fdao.retornaFornecedorPorCodigo(p.getCodFornecedor());
                    modeloPesquisaProduto.addRow(new String[]{Integer.toString(p.getCodProduto()), p.getNome(), p.getTamanho(), Double.toString(p.getPreco()), Integer.toString(p.getQuantidade())});
                }
            }

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Erro: " + ex.getMessage(), "Erro", 0);
        }
}//GEN-LAST:event_txtPesquisaProdutoKeyReleased

    private void tabPesquisaProdutoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabPesquisaProdutoMouseClicked
}//GEN-LAST:event_tabPesquisaProdutoMouseClicked

    private void btnAddProdutoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddProdutoActionPerformed
        if (!txtQtd.getText().isEmpty()) {

            int linha = tabPesquisaProduto.getSelectedRow();

            rotValorVenda.setText(Double.toString(valorVenda));

            rotValorParcela.setText(Double.toString(valorVenda));

            if (linha == -1) {
                JOptionPane.showMessageDialog(null, "Erro: Você não selecionou o produto", "Erro", 0);
            } else {

                try {
                    ProdutoDAO pdao = new ProdutoDAO();
                    Produto p = pdao.retornaProdutoPorCodigo(Integer.parseInt(tabPesquisaProduto.getValueAt(linha, 0).toString()));
                    p.setQuantidade(Integer.parseInt(txtQtd.getText()));

                    valorVenda += p.getPreco() * Integer.parseInt(txtQtd.getText());
                    modeloProdutoSelecionado.addRow(new String[]{Integer.toString(p.getCodProduto()), p.getNome(), Double.toString(p.getPreco()), Integer.toString(p.getQuantidade())});

                    rotValorVenda.setText(Double.toString(valorVenda));

                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(null, "Erro: " + ex.getMessage(), "Erro", 0);
                }


            }
        } else {
            JOptionPane.showMessageDialog(null, "Erro: Você não preencheu o campo QUANTIDADE.", "Erro", 0);
        }
}//GEN-LAST:event_btnAddProdutoActionPerformed

    private void txtNomeClienteKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNomeClienteKeyReleased
}//GEN-LAST:event_txtNomeClienteKeyReleased

    private void txtPesquisaClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPesquisaClienteActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txtPesquisaClienteActionPerformed

    private void txtPesquisaClienteKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtPesquisaClienteKeyReleased
        modeloPesquisaCliente.setNumRows(0);

        ArrayList<Cliente> listaCliente;

        try {
            ClienteDAO cdao = new ClienteDAO();
            if (!txtPesquisaCliente.getText().isEmpty()) {
                if (filtro.getSelectedItem().toString().equals("Nome")) {
                    listaCliente = cdao.retornaClientePorNome(txtPesquisaCliente.getText().toUpperCase());
                } else if (filtro.getSelectedItem().toString().equals("Código")) {
                    listaCliente = cdao.retornaClientePorCod(Integer.parseInt(txtPesquisaCliente.getText().toUpperCase()));
                } else {
                    listaCliente = cdao.retornaClientePorCpf(txtPesquisaCliente.getText().toUpperCase());
                }
                for (Cliente c : listaCliente) {
                    modeloPesquisaCliente.addRow(new String[]{Integer.toString(c.getCodCliente()), c.getNome(), c.getCpf(), c.getRua(), Integer.toString(c.getNumero()), c.getCidade()});
                }
            }


        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Erro: " + ex.getMessage(), "Erro", 0);
        }
}//GEN-LAST:event_txtPesquisaClienteKeyReleased

    private void tabPesquisaClienteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabPesquisaClienteMouseClicked
        int linha = tabPesquisaCliente.getSelectedRow();
        try {
            ClienteDAO cdao = new ClienteDAO();
            Cliente c = cdao.retornaClientePorCodigo(Integer.parseInt(tabPesquisaCliente.getValueAt(linha, 0).toString()));
            txtCodigocliente.setText(Integer.toString(c.getCodCliente()));
            txtNomeCliente.setText(c.getNome());

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Erro: " + ex.getMessage(), "Erro", 0);
        }
}//GEN-LAST:event_tabPesquisaClienteMouseClicked

    private void txtPesquisaProdutoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPesquisaProdutoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtPesquisaProdutoActionPerformed

    private void txtQtdKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtQtdKeyReleased
        try {
            Integer.parseInt(txtQtd.getText());
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "No campo quatidade só é permitido números!", "Aviso", 0);
            txtQtd.setText("");
        }
    }//GEN-LAST:event_txtQtdKeyReleased

    private void nParcelasItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_nParcelasItemStateChanged
        rotValorParcela.setText(Double.toString(valorVenda / Integer.parseInt(nParcelas.getSelectedItem().toString())));
}//GEN-LAST:event_nParcelasItemStateChanged

    private void formWindowOpened_PesquisaProduto(java.awt.event.WindowEvent evt) {

        //TABELA
        String[] colunas = new String[]{"", "", "", "", ""};
        String[][] dados = new String[][]{};

        modeloPesquisaProduto = new DefaultTableModel(dados, colunas);

        tabPesquisaProduto.setModel(modeloPesquisaProduto);

        tabPesquisaProduto.getTableHeader().getColumnModel().getColumn(0).setHeaderValue("Código");
        tabPesquisaProduto.getTableHeader().getColumnModel().getColumn(1).setHeaderValue("Nome");
        tabPesquisaProduto.getTableHeader().getColumnModel().getColumn(2).setHeaderValue("Tamanho");
        tabPesquisaProduto.getTableHeader().getColumnModel().getColumn(3).setHeaderValue("Preço");
        tabPesquisaProduto.getTableHeader().getColumnModel().getColumn(4).setHeaderValue("Qtd");

        tabPesquisaProduto.setPreferredScrollableViewportSize(new Dimension(2300, 0));

    }

    private void formWindowOpened_PesquisaCliente(java.awt.event.WindowEvent evt) {

        //TABELA
        String[] colunas = new String[]{"", ""};
        String[][] dados = new String[][]{};

        modeloPesquisaCliente = new DefaultTableModel(dados, colunas);

        tabPesquisaCliente.setModel(modeloPesquisaCliente);
        tabPesquisaCliente.getTableHeader().getColumnModel().getColumn(0).setHeaderValue("Nome");
        tabPesquisaCliente.getTableHeader().getColumnModel().getColumn(1).setHeaderValue("CPF");

        tabPesquisaCliente.setPreferredScrollableViewportSize(new Dimension(2300, 0));

    }

    private void formWindowOpened_ProdutoSelecionado(java.awt.event.WindowEvent evt) {

        //TABELA
        String[] colunas = new String[]{"", "", "", ""};
        String[][] dados = new String[][]{};

        modeloProdutoSelecionado = new DefaultTableModel(dados, colunas);

        tabProdutoSelecionados.setModel(modeloProdutoSelecionado);
        tabProdutoSelecionados.getTableHeader().getColumnModel().getColumn(0).setHeaderValue("Código");
        tabProdutoSelecionados.getTableHeader().getColumnModel().getColumn(1).setHeaderValue("Nome");
        tabProdutoSelecionados.getTableHeader().getColumnModel().getColumn(2).setHeaderValue("Preco");
        tabProdutoSelecionados.getTableHeader().getColumnModel().getColumn(3).setHeaderValue("Quantidade");

        tabProdutoSelecionados.setPreferredScrollableViewportSize(new Dimension(2300, 0));

    }

    public void primeiraLeitura() {


        txtCodigocliente.setText("");
        txtNomeCliente.setText("");
        txtPesquisaCliente.setText("");
        txtPesquisaProduto.setText("");
        txtQtd.setText("");
        rotValorVenda.setText("");


        btnSalvar.setEnabled(false);
        btnNovo.setEnabled(true);
        btnCancelar.setEnabled(false);

        txtNomeCliente.setEnabled(false);
        txtPesquisaCliente.setEnabled(false);
        txtPesquisaProduto.setEnabled(false);
        txtQtd.setEnabled(false);
        txtCodigocliente.setEnabled(false);

        btnAddProduto.setEnabled(false);
        boxTipoPagamento.setEnabled(false);
        filtro.setEnabled(false);

        tabPesquisaCliente.setEnabled(false);
        tabPesquisaProduto.setEnabled(false);
        tabProdutoSelecionados.setEnabled(false);


        formWindowOpened_PesquisaProduto(null);
        formWindowOpened_PesquisaCliente(null);
        formWindowOpened_ProdutoSelecionado(null);


        txtPesquisaProdutoKeyReleased(null);
        txtPesquisaClienteKeyReleased(null);

        setVisible(true);

    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox boxTipoPagamento;
    private javax.swing.JButton btnAddProduto;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnNovo;
    private javax.swing.JButton btnSalvar;
    private javax.swing.JComboBox filtro;
    private javax.swing.JComboBox filtroP;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JTabbedPane jTabbedPane3;
    private javax.swing.JLabel lValorTotal1;
    private javax.swing.JComboBox nParcelas;
    private javax.swing.JPanel rotParcela;
    private javax.swing.JTextPane rotValorParcela;
    private javax.swing.JLabel rotValorVenda;
    private javax.swing.JTable tabPesquisaCliente;
    private javax.swing.JTable tabPesquisaProduto;
    private javax.swing.JTable tabProdutoSelecionados;
    private javax.swing.JTextField txtCodigocliente;
    private javax.swing.JTextField txtData;
    private javax.swing.JTextField txtNomeCliente;
    private javax.swing.JTextField txtPesquisaCliente;
    private javax.swing.JTextField txtPesquisaProduto;
    private javax.swing.JTextField txtQtd;
    // End of variables declaration//GEN-END:variables
}
